#!/usr/bin/env python

from user_class import User

def init ( l, admin = 0, login = 0 ):
	from liwe import parts

	u = User ( l )

	if login and int ( login ) == 1:
		parts.add ( l.layman, [ "base" ] )

	parts.add ( l.layman, [ "form" ] )
	#parts.add ( l.layman, [ "ext" ] )
	l.layman.add_js ( "modules/user/js/user2.js" )
	l.layman.add_css ( "modules/user/gfx/user.css" )

	if admin and int ( admin ):
		group_admin = u.cfg.get ( 'group_enabled', 0 )

		parts.add ( l.layman, [ "ext" ] )
		parts.add_wwl ( l.layman, [ "accordion" ] )

		#l.layman.add_js ( "modules/user/js/user.admin.js" )
		l.layman.add_js ( "modules/user/js/user2.admin.js" )
		l.layman.add_css ( "modules/user/gfx/user.admin.css" )

		if group_admin: 
			parts.add_wwl ( l.layman, [ "panels" ] )
			l.layman.add_js ( "modules/user/js/group.admin.js" )

		l.layman.add_js_code ( "user.init ( function () { user.admin.init ( %s ); } );" % group_admin )
	else:
		l.layman.add_js_code ( "user.init ();" )
		
	return ''

def show_login ( liwe ):
	"""
	"""
	from liwe import parts

	res = []

	res.append ( '<div id="user-login-box">' )

	parts.add ( liwe.layman, [ "ext" ] )

	if liwe.pyhp.session.data.get ( "uid" ):
		res.append ( "UID: %d" % liwe.pyhp.session.data.get ( 'uid' ) )
	else:
		res.append ( '<a href="javascript:user.login_box()">Accedi / Registrati</a>' )

	res.append ( '</div>' )

	return { "_txt" : ''.join ( res ) }
